#pragma once
#include "Entity.h"
#include "Struct.h"

class ModelEntity : public Entity {
public:
	ModelEntity(ModelType type, int ID) : m_type(type), m_ID(ID) { create(type, ID); }

	void create(ModelType type, int ID);

	void updateState() override;

	ModelType modelType() const { return m_type; }

	EntityType type() const override { return EntityType::MODEL; }
	RenderOrder renderOrder() const override { return Proj::isSSQK() ? RenderOrder::Seventh : RenderOrder::Opaque; }

private:
	ModelEntity(Entity* parent) : Entity(parent) {}

	void fillOneMesh(ModelType type, int meshIndex = 0, bool asChild = false);

	void attachEllipseEffect(Entity* e);

	void enableLight() { _setLightEffect(true); }
	void disableLight() { _setLightEffect(false); }

	void _setLightEffect(bool enable) {
		const auto& children = Entity::children();
		if (children.empty()) this->setLightEnabled(enable);
		else
			for (auto& child : children)
				child->setLightEnabled(enable);
	}

	ModelType m_type;
	int m_ID;

	bool m_hasNewMatColor = false;
};